package com.example.day09question.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.example.day09question.R;
import com.example.day09question.adapter.RvAdapter;
import com.example.day09question.bean.RvBean;
import com.example.day09question.presenter.Netreok;
import com.example.day09question.view.NetView;

import java.util.ArrayList;

public class OneFragment extends Fragment implements NetView {


    private View view;
    private RecyclerView mRv;
    private ArrayList<RvBean.DataBean.DatasBean> list;
    private RvAdapter rvAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_one, container, false);
        Netreok netreok = new Netreok(this);
        netreok.setdata();
        initView(inflate);
        return inflate;
    }

    private void initView(View inflate) {
        mRv = (RecyclerView) inflate.findViewById(R.id.rv);
        list = new ArrayList<>();
        mRv.setLayoutManager(new LinearLayoutManager(getActivity()));
        rvAdapter = new RvAdapter(getContext(), list);
        mRv.setAdapter(rvAdapter);

    }

    @Override
    public void setData(RvBean bean) {
        list.addAll(bean.getData().getDatas());
        rvAdapter.notifyDataSetChanged();
    }

    @Override
    public void shoutow(String string) {
        Toast.makeText(getActivity(), string, Toast.LENGTH_SHORT).show();
    }
}
